%include "I:\workdata\706727\Build\Directories_And_SampleRestrictions.sas";
%include "I:\workdata\706727\Build\Programs.sas";
libname dstform "\\srvfsenas1\data\Formater\SAS formater i Danmarks Statistik\SAS_datasaet\Sundhed";
libname exp "I:\Workdata\706727\Build\Data";

/**** Price data ****/
data pricehel;
set raw.Lprdrgshelv;
run;

data pricehel;
set pricehel;
if c_kontaars="." then c_kontaars="";
spec2=c_spec*1;
run;

data priceamb;
set raw.Lprdrgsambv;
run;

proc sql;
create table fpriceamb as select distinct pnr,recnum,d_inddto,c_adiag,c_kontaars,c_pattype,c_spec,sum(v_pris) as v_pris from priceamb
group by pnr,recnum
order by pnr,recnum;
quit;

/* Take average price within patient type and diagnosis */

* Hel *;
data pricehospdiags_hel;
set pricehel;
year=substr(C_CSC_DBTSTDT,1,4)*1;
month=substr(C_CSC_DBTSTDT,5,2)*1;
diag2=substr(c_adiag,2,2);
diag1=substr(c_adiag,2,1);
if month<4 then year2=year-1;
if month>=4 then year2=year;
if year2=2000 then dprice=v_totpris*1000*(145.46/97.11); 
if year2=2001 then dprice=v_totpris*1000*(145.46/100.35); 
if year2=2002 then dprice=v_totpris*1000*(145.46/102.59); 
if year2=2003 then dprice=v_totpris*1000*(145.46/105.57); 
if year2=2004 then dprice=v_totpris*1000*(145.46/106.81); 
if year2=2005 then dprice=v_totpris*1000*(145.46/108.05);
if year2=2006 then dprice=v_totpris*1000*(145.46/113.25); 
if year2=2007 then dprice=v_totpris*1000*(145.46/116.90); 
if year2=2008 then dprice=v_totpris*1000*(145.46/123.02);
if year2=2009 then dprice=v_totpris*1000*(145.46/126.86);
if year2=2010 then dprice=v_totpris*1000*(145.46/128.76);
if year2=2011 then dprice=v_totpris*1000*(145.46/129.52); 
if year2=2012 then dprice=v_totpris*1000*(145.46/131.93); 
if year2=2013 then dprice=v_totpris*1000*(145.46/132.44);
if year2=2014 then dprice=v_totpris*1000*(145.46/133.84);
if year2=2015 then dprice=v_totpris*1000*(145.46/134.92);
if year2=2016 then dprice=v_totpris*1000*(145.46/136.66); /* Price data only available until 2016 - does not matter as average price over time is used */
run;

proc sort data=pricehospdiags_hel;
by diag1 c_pattype;
run;

proc means data=pricehospdiags_hel nway noprint;
var dprice;
by diag1 c_pattype;
output out=avhelprice1 mean=mhelprice1;
run;

data exp.avhelprice1;
set avhelprice1;
run;

proc sort data=pricehospdiags_hel;
by diag2 c_pattype;
run;

proc means data=pricehospdiags_hel nway noprint;
var dprice;
by diag2 c_pattype;
output out=avhelprice2 mean=mhelprice2;
run;

data exp.avhelprice2;
set avhelprice2;
run;


* Amb *;
data pricehospdiags_amb;
set fpriceamb;
diag2=substr(c_adiag,2,2);
diag1=substr(c_adiag,2,1);
year=year(d_inddto);
month=month(d_inddto);
if month<4 then year2=year-1;
if month>=4 then year2=year;
if year2=2000 then dprice=v_pris*1000*(145.46/97.11); 
if year2=2001 then dprice=v_pris*1000*(145.46/100.35); 
if year2=2002 then dprice=v_pris*1000*(145.46/102.59); 
if year2=2003 then dprice=v_pris*1000*(145.46/105.57); 
if year2=2004 then dprice=v_pris*1000*(145.46/106.81); 
if year2=2005 then dprice=v_pris*1000*(145.46/108.05);
if year2=2006 then dprice=v_pris*1000*(145.46/113.25); 
if year2=2007 then dprice=v_pris*1000*(145.46/116.90); 
if year2=2008 then dprice=v_pris*1000*(145.46/123.02);
if year2=2009 then dprice=v_pris*1000*(145.46/126.86);
if year2=2010 then dprice=v_pris*1000*(145.46/128.76);
if year2=2011 then dprice=v_pris*1000*(145.46/129.52); 
if year2=2012 then dprice=v_pris*1000*(145.46/131.93); 
if year2=2013 then dprice=v_pris*1000*(145.46/132.44);
if year2=2014 then dprice=v_pris*1000*(145.46/133.84);
if year2=2015 then dprice=v_pris*1000*(145.46/134.92);
if year2=2016 then dprice=v_pris*1000*(145.46/136.66); /* Price data only available until 2016 - does not matter as average price over time is used */
run;

proc sort data=pricehospdiags_amb;
by diag1 c_pattype;
run;

proc means data=pricehospdiags_amb nway noprint;
var dprice;
by diag1 c_pattype;
output out=avambprice1 mean=mambprice1;
run;

data exp.avambprice1;
set avambprice1;
run;

proc sort data=pricehospdiags_amb;
by diag2 c_pattype;
run;

proc means data=pricehospdiags_amb nway noprint;
var dprice;
by diag2 c_pattype;
output out=avambprice2 mean=mambprice2;
run;

data exp.avambprice2;
set avambprice2;
run;


